/*
 * File:   Salomon.h
 * Author: jcrada
 *
 * Created on 12 November 2010, 8:50 AM
 */

#ifndef ECB_SALOMON_H
#define	ECB_SALOMON_H

#include "ecb/base/Problem.h"

namespace ecb {

    /* Source:
     * @incollection{springer-dif.evo,
        Author = {Price, Kenneth and Storn, Rainer M. and Lampinen, Jouni A.},
        title={{Appendix}},
        booktitle = {Differential Evolution: A Practical Approach to Global Optimization},
        series={Natural Computing Series},
        editor={Rozenberg, G. and Bäck, Th. and Eiben, A. E. and Kok, J. N. and Spaink, H. P.},
        publisher = {Springer-Verlag Berlin Heidelberg},
        pages = {513-533},
        year = {2005}
        }
     */
    class Salomon : public Problem {
    public:

        Salomon(const std::string& id = "Salomon", const std::string& name = "Salomon",
                int dimensions = 0, scalar minimum = -100, scalar maximum = 100,
                bool minimization = true) :
        Problem(id, name, dimensions, minimum, maximum, minimization) { }

        scalar f(const std::vector<scalar>& x) {
            scalar sum = 0.0;
            for (size_t i = 0; i < x.size(); ++i) {
                sum += x[i] * x[i];
            }
            return -std::cos(2.0 * M_PI * std::sqrt(sum)) + 0.1 * std::sqrt(sum) + 1.0;
        }
    };

}


#endif	/* ECB_SALOMON_H */

